'''
Created on 26/04/2010

@author: Mar
'''


from threading import Thread

class ThreadPrinter(Thread):
    
    def __init__(self, queuePrint, aPrinter, aReadyQ):
        Thread.__init__(self)
        self.queuePrint = queuePrint
        self.printer = aPrinter
        self.readyQueue = aReadyQ
        
    def run(self):
        while (True):
            pcb = self.queuePrint.get()
            self.printer.executePCB(pcb)
            priority = pcb.getPriority()
            self.readyQueue.put((priority,pcb))
            if (len(pcb.program.instructions) == pcb.getPC()):
                pcb.toFinished() 
        